package com.distribution.system.controller;

import com.distribution.common.core.controller.BaseController;
import com.distribution.common.core.domain.AjaxResult;
import com.distribution.common.core.page.TableDataInfo;
import com.distribution.system.domain.entity.CmccDaChildCard;
import com.distribution.system.domain.req.CmccDaCardDelReq;
import com.distribution.system.domain.req.CmccDaProductListReq;
import com.distribution.system.domain.req.CmccDaChildCardAddReq;
import com.distribution.system.service.CmccDaChildCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author: GodLu
 * @create: 2024-04-10 16:09
 * @description: TODO
 */
@RestController
@RequestMapping("/cmccDaChildCard")
@Slf4j
public class CmccDaChildCardController extends BaseController {
    @Resource
    CmccDaChildCardService cmccDaChildCardService;

    /**
     * 分卡列表
     */
    @PostMapping("/selectChildCardList")
    public TableDataInfo list(@RequestBody CmccDaProductListReq cmccDaProductListReq) {
        startPage();
        List<CmccDaChildCard> cmccDaChildCardList = cmccDaChildCardService.childCardList(cmccDaProductListReq);
        return getDataTable(cmccDaChildCardList);
    }

    /**
     * 添加分卡
     */
    @PostMapping("/addChildCard")
    AjaxResult add(@RequestBody @Valid CmccDaChildCardAddReq cmccDaChildCardAddReq) {
        cmccDaChildCardService.saveChildCard(cmccDaChildCardAddReq);
        return success();
    }

    /**
     * 修改分卡
     */
    @PostMapping("/updateChildCard")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult update(@RequestBody CmccDaChildCard cmccDaChildCard) {
        cmccDaChildCardService.updateChildCard(cmccDaChildCard);
        return success();
    }

    /**
     * 删除分卡
     */
    @PostMapping("/delChildCard")
    AjaxResult delChildCard(@RequestBody @Valid CmccDaCardDelReq cmccDaCardDelReq) {
        //按照id 删除推荐卡信息
        cmccDaChildCardService.removeById(cmccDaCardDelReq.getId());
        return success();
    }
}
